﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGH
{
    class Select
    {
        //GEN的过程
        //先构造CISET，再利用CISET排样，再修正价值，更新毛坯剩余量

        //restDemand毛坯序号、毛坯剩余需求及毛坯价值
        public static void select(Global global)
        {
            int determinedK;
            List<int[]> currentBlank=new List<int[]>();
           // int kMax = Method.getMax(Constant.restDemand);
            bool isExist = false;
            List<int[]> restDemand = global.restDemand;
            int n = restDemand.Count;
            int kMax = Method.getMax(restDemand);
            for (int i = kMax; i >= 1; i--)
            {
                int nB = 0;
                double sB = 0;
                List<int[]> ciSet = new List<int[]>();
                for (int j = 0; j < n; j++)
                {
                    double ii = i + 0.0;
                    int b = (int)(restDemand[j][1] / ii);
                    if (b > 0)
                    {
                        double d=Constant.diameter[restDemand[j][0]];
                        nB += 1;
                        sB += b*d*d*Constant.PI/4 ;
                        ciSet.Add(restDemand[j]);
                    }
                }
                if (nB >= global.theta && sB >= global.beta * Constant.sheetLength * Constant.sheetWidth)
                {
                    determinedK = i;
                    currentBlank = ciSet;
                    isExist = true;
                    break;
                }
            }
            if (isExist == false)
            {
                currentBlank = restDemand;
                determinedK = 1;
            }
            global.CISET = currentBlank;
        }
        
    }
}
